<template>
  <div class="wrapper">
    <video-player class="video-player vjs-custom-skin"
                  ref="videoPlayer"
                  :playsinline="false"
                  :options="playerOptions"
                  @play="onPlayerPlay($event)"
                  @pause="onPlayerPause($event)"
                  @fullscreenchange="handleEnterFullScreen($event)"
                  :webkit-playsinline='true'
                  :x-webkit-airplay='true'
                  :x5-video-player-fullscreen='true'
                  :x5-video-ignore-metadata='true'
                  @click="handleClick"></video-player>
  </div>
</template>

<script>
export default {
  name: 'DetailVideo',
  props: {
    source: {
      type: String,
      default: 'http://video.699pic.com/videos/55/39/77/C1MCR89yTctd1528553977.mp4'
    },
    video: {
      type: Object
    }
  },
  data () {
    return {
      // 视频播放
      playerOptions: {
        playbackRates: [0.7, 1.0, 1.5, 2.0], // 播放速度
        autoplay: false, // 如果true,浏览器准备好时开始回放。
        muted: false, // 默认情况下将会消除任何音频。
        loop: false, // 导致视频一结束就重新开始。
        preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: 'zh-CN',
        aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
        fluid: true,
        sources: [{
          type: 'video/mp4',
          src: this.video.url
        }],
        poster: this.video.img,
        width: document.documentElement.clientWidth,
        notSupportedMessage: '此视频暂无法播放，请稍后再试',
        controlBar: {
          timeDivider: true,
          durationDisplay: true,
          remainingTimeDisplay: false,
          fullscreenToggle: true
        }
      }
    }
  },
  methods: {
    onPlayerPlay (player) {
      // player.play()
    },
    onPlayerPause (player) {
      player.pause()
    },
    handleEnterFullScreen (player) {
      console.log(1)
    },
    handleClick () {
      console.log(2)
    }
  },
  computed: {
    player () {
      return this.$refs.videoPlayer.player
    },
    isFullscreen () {
      return this.player.isFullscreen()
    }
  }
}
</script>

<style lang="stylus" scoped>
.wrapper >>> .video-js .vjs-big-play-button
  height 3em
  width 3em
  line-height 3em
  border-radius 1.5em

.wrapper
  min-height 100%
  touch-action none

  .vjs-custom-skin
    touch-action none

// .wrapper >>> .video-js .vjs-play-control.vjs-playing .vjs-icon-placeholder:before, .vjs-icon-pause:before
// font-size 20px
// display flex
// align-items center
// justify-content center
.wrapper >>> .vjs-custom-skin>.video-js .vjs-control-bar
  font-size 20px
</style>
